
//
//  BottomView.m
//  1243
//
//  Created by ym on 16/6/29.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "BottomView.h"
#import "ChoseScrollView.h"
#import "OneMoneyCollectionViewCell.h"


static NSString *identifier = @"CELL";


@interface BottomView ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation BottomView
{
    UICollectionView  *mcollectionView;
    CGRect              *mframe;
}
- (instancetype)initWithFrame:(CGRect)frame {
    if (self  = [super initWithFrame:frame]) {
        
        mframe = &frame;
        
        self.backgroundColor = [UIColor redColor];
        
        ChoseScrollView *choseView = [[ChoseScrollView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 50)];
   
        choseView.passIndexBlock = ^void(NSInteger index) {
            [self jumpToIndex:index-1];
        };
        [self addSubview:choseView];
        
        
//        //集合视图
        UICollectionViewFlowLayout *flowLayout= [[UICollectionViewFlowLayout alloc] init];
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;//滚动方向
        flowLayout.minimumLineSpacing = 15.0;//行间距(最小值)
        flowLayout.minimumInteritemSpacing = 0.0;//item间距(最小值)
        flowLayout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width/2 - 15, ([UIScreen mainScreen].bounds.size.width/2 - 15)*1.5);//item的大小
        flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);//设置section的边距
        //第二个参数是cell的布局
        mcollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50, [UIScreen mainScreen].bounds.size.width, frame.size.height - 110) collectionViewLayout:flowLayout];
        mcollectionView.dataSource = self;
        mcollectionView.delegate = self;
        mcollectionView.backgroundColor = [UIColor whiteColor];
        mcollectionView.showsVerticalScrollIndicator = NO;
        //1 注册复用cell(cell的类型和标识符)(可以注册多个复用cell, 一定要保证重用标示符是不一样的)注册到了collectionView的复用池里
        [mcollectionView registerClass:[OneMoneyCollectionViewCell class] forCellWithReuseIdentifier:identifier];

        //第一个参数:返回的View类型
        //第二个参数:设置View的种类(header, footer)
        //第三个参数:设置重用标识符
        [self addSubview: mcollectionView];
        
//        [self creatBut];
    }
    return self;
}

#pragma mark ---- 点击刷新
- (void)jumpToIndex:(NSInteger )index {
    NSLog(@"%ld",index);
}



- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
}

#pragma mark -- 自定义cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    OneMoneyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
   
        return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (self.jumpDetailBlock) {
        self.jumpDetailBlock();
    }
}


@end
